
bt.module({builder: function(bt) {
    var loadMoreHot = function(count) {
        j$('#ajax-more').show();
        j$('#ajax-more').css("visibility", "visible");
        j$.ajax({
            url: '/explore/hot_more/?count=' + count,
            success: function(html){
                j$('#hot_trips_wrapper').replaceWith(html);
                _initLoadMoreEvent();
                j$(window).resize();
            }
        });
        return false;
    };

    var loadMoreLive = function(count) {
        j$('#ajax-more').show();
        j$('#ajax-more').css("visibility", "visible");
        j$.ajax({
            url: '/explore/live_more/?count=' + count,
            success: function(html){
                j$('#feeds_wrapper').replaceWith(html);
                _initLoadMoreEvent();
                _initReplyPanelEvent();
                _ellipsisNames();
                bt.reply.initLocationEvent();
                j$(window).resize();
            }
        });
        return false;
    };

    var _initLoadMoreEvent = function() {
        j$("#load-more.hot").click(function() {
            loadMoreHot(parseInt(j$("#load-more.hot").attr("data-count")));
        });

        j$("#load-more.live").click(function() {
            loadMoreLive(parseInt(j$("#load-more.live").attr("data-count")));
        });

        j$('img.cover-img').each(function(){
            bt.misc.centerAlignImg(j$(this), 313, 566);
        });

        j$('img.cover-img').bind('load', function(){
            bt.misc.centerAlignImg(j$(this), 313, 566);
        });

        j$('img.photo').each(function(){
            bt.misc.centerAlignImg(j$(this), 284, 508);
        });

        j$('img.photo').bind('load', function(){
            bt.misc.centerAlignImg(j$(this), 284, 508);
        });

        /*
        $("img.cover-img, img.photo").show().lazyload({
            effect: 'fadeIn',
            threshold : 200
        });
        */
    }

    var _initReplyPanelEvent = function() {
        bt.reply.bind_like_func(j$('a.like-btn'), 'click');
        bt.reply.bind_expand_cmts_func(j$('a.comment-btn'), 'click');
        bt.reply.bind_reply_somebody_func(j$('ul.comments a.btn-reply'), 'click');
        bt.reply.bind_post_comment_func(j$('form.comment'), 'submit');
        bt.reply.bind_post_comment_func(j$('form.comment .btn-comment'), 'click');
    };

    var _ellipsisNames = function() {
        var ellipsis_settings = {
            max_rows: 1,
            alt_text_t: true,
            whole_word: false
        };
        j$("#feeds .title .trip-name").each(function() {
            j$(this).ThreeDots(ellipsis_settings);
        });
        j$("#feeds .info .location").each(function() {
            j$(this).ThreeDots(ellipsis_settings);
        });
    };


    j$(document).ready(function() {
        _initLoadMoreEvent();
        _ellipsisNames();
    });

    bt.explore.loadMoreHot = loadMoreHot;
    bt.explore.loadMoreLive = loadMoreLive;

}});
